Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Partial Class TheatreStaff_Session
	Inherits System.Web.UI.Page
	Protected Sub Page_Load(sender As Object, e As EventArgs)
		srcgrdSession.SelectParameters("username").DefaultValue = Page.User.Identity.Name
		'srcgrdSchedule.SelectParameters["username"].DefaultValue = Page.User.Identity.Name;
		'grdSpecialTickets.Sort("MovieTitle", SortDirection.Ascending);
		Dim connectionString As String
		connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

		Dim con As New SqlConnection(connectionString)
		Dim cmd As New SqlCommand("SELECT TheatreId from TheatreStaff WHERE TheatreStaffUsername=@username", con)

		cmd.Parameters.AddWithValue("@username", Page.User.Identity.Name)

		Using con
			con.Open()
			Dim TheatreID As Object = cmd.ExecuteScalar()
			If TheatreID IsNot Nothing Then
				lblId.Text = TheatreID.ToString()
			End If
		End Using
		Dim con1 As New SqlConnection(connectionString)
		Dim cmd1 As New SqlCommand("SELECT Theatrename from Theatre WHERE Theatreid=@theatreid", con1)

		cmd1.Parameters.AddWithValue("@theatreid", lblId.Text)


		Using con1
			con1.Open()
			Dim Theatrename As Object = cmd1.ExecuteScalar()

			If Theatrename IsNot Nothing Then

				Label5.Text = Theatrename.ToString()
			End If
		End Using

    End Sub
    Private Sub Page_Load()
        If Not Page.IsPostBack Then
            grdSession.SelectedIndex = 0
        End If
        Label15.Text = String.Empty
        Label16.Text = String.Empty
    End Sub
    'protected void Cancel(object sender, EventArgs e)
    '{

    '    txtSessionTimeI.Text = string.Empty;
    '    ddlCinemaI.SelectedIndex = -1;
    '    //txtDurationI.Text = string.Empty;
    '    Label15.Text = string.Empty;
    '    Label16.Text = string.Empty;
    '    grdSession.DataBind();
    '}
    Protected Sub Clear(ByVal sender As Object, ByVal e As EventArgs)
        Label15.Text = String.Empty
        Label16.Text = String.Empty
    End Sub
    Protected Sub OnItemUpdated_Click(ByVal sender As Object, ByVal e As DetailsViewUpdatedEventArgs)
        grdSession.DataBind()
        Label15.Text = String.Empty
        Label16.Text = String.Empty
    End Sub
    'protected void InsertS_Click(object sender, EventArgs e)
    '{
    '    Label15.Text = string.Empty;
    '    Label16.Text = string.Empty; 
    '    string connectionString;
    '    connectionString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    '    SqlConnection con = new SqlConnection(connectionString);
    '    SqlConnection con1 = new SqlConnection(connectionString);
    '    SqlCommand cmd1 = new SqlCommand("INSERT session2(time,cinema) values (@time,@cinema)", con1);
    '    SqlCommand cmd = new SqlCommand("SELECT time,cinema from session2,TheatreStaff,Cinema WHERE TheatreStaff.TheatreId=Cinema.TheatreId AND Cinema.CinemaId=session2.cinema AND Cinema.TheatreId=@TheatreId AND session2.time=@time AND session2.cinema=@cinema", con);
    '    string ParamString = lblId.Text;
    '    Int32 RowCount;
    '    Boolean HasS;

    '    cmd.Parameters.AddWithValue("@TheatreId", ParamString);
    '    cmd.Parameters.AddWithValue("@time", txtSessionTimeI.Text );
    '    cmd.Parameters.AddWithValue("@cinema", ddlCinemaI.SelectedValue);

    '    using (con)
    '    {
    '        con.Open();
    '        SqlDataReader Reader = cmd.ExecuteReader();

    '        if (Reader.HasRows)
    '        {

    '            Label15.Text = "The session" + " already exist in the database!";
    'lblCheck.Text = string.Empty;
    'ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "Focus", "<script language='JavaScript' 'showInsert();'/>");

    '        HasS = true;

    '    }
    '    else
    '    {
    '        HasS = false;

    '    }
    '}
    'using (con1)
    '{
    '    con1.Open();
    '    if (HasS == false)
    '    {

    '        cmd1.Parameters.AddWithValue("@time", txtSessionTimeI.Text);
    '        cmd1.Parameters.AddWithValue("@cinema", ddlCinemaI.SelectedValue );
    '        //cmd1.Parameters.AddWithValue("@Duration", txtDurationI.Text);
    '        RowCount = cmd1.ExecuteNonQuery();
    '        txtSessionTimeI.Text = string.Empty;
    '        ddlCinemaI.SelectedIndex =-1;
    'txtDurationI.Text = string.Empty;
    'if (RowCount > 0)
    '{
    '            Label16.Text = "The session " + "has been added sucessfully!";
    '            //lblCorrect.Visible = true;


    '            //}
    '        }

    '    }
    '    grdSession.DataBind();
    '}
    Protected Sub function2(ByVal sender As Object, ByVal e As EventArgs)

        Dim tb2 As TextBox = DirectCast(dtlSpecial.FindControl("txtSessionTime"), TextBox)
        Dim tb3 As Label = DirectCast(dtlSpecial.FindControl("Label6"), Label)
        Label3.Text = tb2.Text


    End Sub
    Protected Sub function4(ByVal sender As Object, ByVal e As EventArgs)

        Dim tb3 As DropDownList = DirectCast(dtlSpecial.FindControl("ddlCinema"), DropDownList)
        Label4.Text = tb3.SelectedItem.Text


    End Sub
    Protected Sub function3(ByVal source As Object, ByVal args As ServerValidateEventArgs)

        Dim tb2 As TextBox = DirectCast(dtlSpecial.FindControl("txtSessionTime"), TextBox)
        Dim tb3 As DropDownList = DirectCast(dtlSpecial.FindControl("ddlCinema"), DropDownList)
        If (Label3.Text = tb2.Text) AndAlso (Label4.Text = tb3.SelectedItem.Text) Then
            Label7.Text = "same"

            args.IsValid = True
        Else

            Dim connectionString As String
            connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
            Dim con As New SqlConnection(connectionString)
            Dim cmd1 As New SqlCommand("SELECT time,cinema from session2 WHERE time=@time AND cinema =@cinema ", con)
            cmd1.Parameters.AddWithValue("@time", tb2.Text)
            cmd1.Parameters.AddWithValue("@cinema", tb3.Text)
            Using con
                con.Open()
                Dim reader As SqlDataReader = cmd1.ExecuteReader()
                If reader.HasRows Then
                    args.IsValid = False
                    Label7.Text = "match"
                Else

                    Label7.Text = "NO maetch"
                End If
            End Using
        End If
    End Sub
End Class
